package top.ahwyy.controller.Action;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import top.ahwyy.controller.impl.cardImpl;
import top.ahwyy.controller.impl.userImpl;
import top.ahwyy.controller.inter.card;
import top.ahwyy.controller.inter.user;
import top.ahwyy.model.userdata;

public class ownAction implements ServletRequestAware, ServletResponseAware {

	HttpServletRequest request = null;
	HttpServletResponse response = null;
	
	public String execute(){
		response.setContentType("text/html;charset=utf-8");
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String un = request.getSession().getAttribute("un").toString();
		card ci = new cardImpl();
		int uid = ci.getUserIdByUn(un);
		user ui = new userImpl();
		userdata ud = ui.getUserDataByUserId(uid);
		
		request.setAttribute("userdata", ud);
		
		return "success";
	}
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;

	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;

	}

}
